package com.gpframework.common.pay.leshua.util;

import com.gpframework.common.config.GpframeworkConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

/**
 * Description:
 * Author:Geno
 * Date:2018/5/28
 * Mail:geno@yeahka.com
 */
@Slf4j
@Component
public class FileUtil {


    public File transfer(MultipartFile multipartFile, String fileName) {
//        String path = getClass().getClassLoader().getResource("").getPath()+"tmp/";
        String path = GpframeworkConfig.getProfile() + "/tmp/";
        File pathFile = new File(path);
        if (!pathFile.exists()) {
            pathFile.mkdirs();
        }
        File file = new File(path + fileName);
        try {
            multipartFile.transferTo(file);
        } catch (IOException e) {
            log.error(e.getMessage());
        }
        return file;
    }
}
